<?php
namespace app\index\controller;
use \think\Controller;
use \think\Request;
use \think\Session;
use \think\Db;

class Sig extends Controller
{
    public function index()
    {
    	return $this->fetch('index',['title'=>'用户注册 - 蒸汽男孩论坛']);
    }

    public function ccp(Request $req)
    {
        $phone = $req->post();
        $data = Db::name('user')->where(['phone' => $phone['phone']])->find();

        if (!empty($data)) {
            $info['status'] = false;
            return json($info);
        } else {
            $data = sendTemplateSMS($phone['phone'],array('1234','1'),"1");
            $info['status'] = true;
            return json($info);

        }
    }

    public function doSig(Request $req)
    {
    	$sql = $req->post();
    	// var_dump($sql);die;
    	if($sql['code'] != 1234) {
    		$this->error('验证码错误');
    	} elseif($sql['pass'] != $sql['rpass']) {
    		$this->error('两次密码不相同');
    	} else {
    		$name = Db::name('user')->where(['nick'=>$sql['nick']])->find();
    		if($name != null) {
    			$this->error('用户名已存在');
    		}
    	}

    	unset($sql['code']);
    	unset($sql['rpass']);
    	$sql['pass'] = md5($sql['pass']);
    	$data = Db::name('user')->insert($sql);
    	if($data > 0) {
    		$this->success('注册成功',url('index/index/index'));
    	} else {
    		$this->error('注册失败');
    	}
    }
}
